package com.shanghaionstar.user.presenter;

import com.onstar.cn.common.util.CommonUtil;
import com.onstar.cn.framework.mvp.base.IMVPScheduler;
import com.onstar.cn.framework.mvp.base.IMVPView;
import com.onstar.cn.framework.mvp.base.core.BasePresenter;
import com.onstar.cn.mag.PlateEngineNumEntity;
import com.shanghaionstar.user.iview.IVehicleInfoView;
import com.shanghaionstar.user.service.PlateEngineService;
import com.shanghaionstar.utils.ApplicationUtil;


/**
 * Created by onstarios on 16/7/25.
 */
public class VehicleInfoPresenter extends BasePresenter<PlateEngineNumEntity> {
    private PlateEngineService service;
    private IVehicleInfoView view;

    public VehicleInfoPresenter(IMVPScheduler mvpScheduler) {
        super(mvpScheduler);
    }

    @Override
    public void setView(IMVPView<PlateEngineNumEntity> view) {
        super.setView(view);
        this.view = (IVehicleInfoView) view;
        service = new PlateEngineService(view.onActivity());
        setServiceProvider(service);
    }


    public void updateVehicleInfo(String insuranceComp, String compulsoryInsuranceExpireDate, String businessInsuranceExpireDate,boolean isQuery) {
        PlateEngineNumEntity plateEngineNumEntity = new PlateEngineNumEntity();
        plateEngineNumEntity.setAccountID(ApplicationUtil.getInstance().getAccountId());
        plateEngineNumEntity.setVin(ApplicationUtil.getInstance().getVin());
        if (!CommonUtil.isNull(insuranceComp)) {
            plateEngineNumEntity.setInsuranceComp(insuranceComp);
        }
        if (!CommonUtil.isNull(compulsoryInsuranceExpireDate)) {
            plateEngineNumEntity.setCompulsoryInsuranceExpireDate(compulsoryInsuranceExpireDate);
        }
        if (!CommonUtil.isNull(businessInsuranceExpireDate)) {
            plateEngineNumEntity.setBusinessInsuranceExpireDate(businessInsuranceExpireDate);
        }
        service.setPlateEngineNumEntity(plateEngineNumEntity, isQuery);
    }

    /**
     * 设置驾驶证日期
     * @param drivingLicenseDate
     * @param isQuery
     */
    public void updateVehicleInfo(String drivingLicenseDate,boolean isQuery) {
        PlateEngineNumEntity plateEngineNumEntity = new PlateEngineNumEntity();
        plateEngineNumEntity.setAccountID(ApplicationUtil.getInstance().getAccountId());
        plateEngineNumEntity.setVin(ApplicationUtil.getInstance().getVin());
        if (!CommonUtil.isNull(drivingLicenseDate)) {
            plateEngineNumEntity.setDrivingLicenseDate(drivingLicenseDate);
        }
        service.setPlateEngineNumEntity(plateEngineNumEntity, isQuery);
    }

}
